package com.wyg.epuser.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wyg.epcommonbase.common.util.AssertUtil;
import com.wyg.epuser.entity.User;
import com.wyg.epuser.mapper.UserMapper;
import com.wyg.epuser.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author WangYongGan
 * @since 2022-05-18
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public User login(User user) {
        return null;
    }

    @Override
    public User selectByName(String username) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        return baseMapper.selectOne(wrapper.lambda().eq(User::getUsername, username));
    }

    @Override
    public void register(User user) {
        AssertUtil.isTrue(selectByName(user.getUsername()) != null, 109, "用户名已存在");
        baseMapper.insert(user);
    }
}
